<%-- 
    Document   : checkResult
    Created on : Oct 14, 2009, 11:59:24 PM
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.sql.*" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <table width="680">
        <form action="calculatorMark.jsp" name="myform" method="post" >

            <jsp:useBean id="Obj" class="DAO.DAOQuery" scope="request" />
            <!-- Kiem tra cau hoi  -->
            <%
            int QuestionTrue = 0;
            int idQuestion;
            float Mark = 0;
            String calcucator = "";
            boolean test = false;
            String[] Question = null;
            String[] checkedID = null;
            String checkedString = "";
            checkedID = request.getParameterValues("Choice");
            Question = request.getParameterValues("QuestionID");
            if (checkedID != null) {
                for (int k = 0; k < checkedID.length; k++) {
                    checkedString += checkedID[k] + ",";
                }
                checkedString = checkedString.substring(0, checkedString.length() - 1);
            }

            for (int i = 0; i < Question.length; i++) {
                idQuestion = Integer.parseInt(Question[i]);
                int DEFAULTTRUE = Obj.counterRowTrue(idQuestion);
                int DEFAULTFALSE = Obj.counterRowFalse(idQuestion);
                int KICKTRUE = Obj.counterCheckTrue(idQuestion, checkedString);
                int KICKFALSE = Obj.counterCheckFalse(idQuestion, checkedString);
                ResultSet rs = Obj.checkTest(idQuestion, checkedString);
                if (rs.next()) {
                    if (DEFAULTTRUE == KICKTRUE && DEFAULTFALSE != KICKFALSE && KICKFALSE != 1 && KICKFALSE != 2 && KICKFALSE != 3 && KICKFALSE != 4) {
                        QuestionTrue++;
                        calcucator += Question[i] + ",";
                        test = true;
                    } else {
                        //out.println("Ban da tra loi sai");
                    }

                }
            }
            //out.println("Ban da tra loi dung : " + QuestionTrue + "/" + Question.length);
            %>
            <p style="font-size:17px">Ban da tra loi dung : <%=QuestionTrue%> / <%=Question.length%></p>
            <!-- The End -->

            <!-- Tinh Diem Cua Nguoi Dung Kick Dung-->
            <%
            if (test == true) {
                calcucator = calcucator.substring(0, calcucator.length() - 1);
                ResultSet rs = Obj.calculatorMark(calcucator);
                while (rs.next()) {
                    Mark += rs.getFloat("Mark");
                }
            %>
            <p style="font-size:18px">Ban duoc so diem la : <%=Mark%></p>
            <%
            } else {
            %>
            <p style="font-size:18px">Ban duoc so diem la : <%=Mark%></p>
            <%
            }
            %>
            <!-- The End -->
            <p style="font-size:18px;color:red">Dap an ma ban da tra loi : </p>

            <!-- Hien Thi Cau Nguoi Tra Loi -->
            <%

            for (int id = 0; id < Question.length; id++) {
                idQuestion = Integer.parseInt(Question[id]);
                ResultSet rs = Obj.selectQuestionLast(1, idQuestion);
                if (rs.next()) {
            %>
            <P style="font-size:18px"> <%=rs.getString("ContentQuestion")%></P>
            <%
                    ResultSet rss = Obj.selectAnswerLasr(idQuestion);
                    while (rss.next()) {
            %>
            <input type="checkbox" name="Choice" disabled="true" <%
                        if (checkedID != null) {
                            for (int k = 0; k < checkedID.length; k++) {
                                checkedString = checkedID[k];
                                if (rss.getString("AnswerID").equals(checkedString)) {
                   %>
                   checked="True"
                   <%                                }
                            }
                        }
                   %>/> <%=rss.getString("AnswerContent")%> <br>
            <%
                    }
                }
            }

            %>
            <!-- The End -->    
            <br>

        </form>
        </table>
    </body>
</html>
